const cloud = require('wx-server-sdk')

cloud.init({
  traceUser: true,
  env: 'photo-duo0u'
})

const db = cloud.database()
const photos = db.collection("photos")



exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  console.log("context", context.OPENID);

  try {
    return await photos.add({
      data: {
        due: new Date(),
        _openid: wxContext.OPENID,
        type: event.type || '其他',
        fileID: event.fileID
      }
    })
  } catch (e) {
    console.error("照片记录增加", e)
  }
}